//
//  BaseModel.m
//  express
//
//  Created by dd on 12/8/14.
//  Copyright (c) 2014 yunqi. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

- (instancetype)initWithData:(NSDictionary *)data
{
    self = [super init];
    if (self)
    {
        _data = [data mutableCopy];
    }
    
    return self;
}

- (id)objectForKey:(NSString *)key
{
    if (![[_data allKeys] containsObject:key]) return nil;
    
    return _data[key];
}

- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key
{
    _data[key] = obj;
}

- (id)objectForKeyedSubscript:(NSString *)key
{
    if (![[_data allKeys] containsObject:key]) return nil;
    
    return _data[key];
}

- (NSString *)stringForKey:(NSString *)key
{
    if (![[_data allKeys] containsObject:key]) return @"";
    
    return [NSString stringWithFormat:@"%@", _data[key]];
}

- (NSDictionary *)data
{
    return _data;
}

@end
